
<form action="<?php echo U('Admin/Basic/Rule/create')?>" id="create-rule" method="post" class="_ajaxSubmit">
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists">
        <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">选择父级 :</div>
        <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
            <select class="form-control radius-none _data" name="pid">
                <option value="0">无父级</option>
                <?php echo $rules;?>
            </select>
        </div>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists">
        <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">规则名称<pub>*</pub> :</div>
        <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
            <input name="title" type="text" autocomplete="off" class="form-control radius-none _data" placeholder="请输入规则名称(仅支持中文和英文)" >
        </div>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists">
        <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">规则标识<pub>*</pub> :</div>
        <div class="col-lg-10 col-md-9 col-xs-7 filed-from padding-none">
            <div class="col-md-2">
                <select name="dir" class="form-control radius-none class-info" for="file">
                    <?php foreach($class_info as $v):?>
                    <option value="<?php echo $v?>"><?php echo $v?></option>
                    <?php endforeach;?>
                </select>
            </div>
            <div class="col-md-2">
                <select name="file" class="form-control radius-none class-info" for="method">

                </select>
            </div>
            <div class="col-md-2">
                <select name="method" class="form-control radius-none class-info">

                </select>
            </div>
            <div class="col-md-6">
                <input name="name" type="text" autocomplete="off" class="form-control radius-none _data" placeholder="规则: 模块名/控制器名/方法名(该字段唯一)">
            </div>
        </div>
    </div>
    <script>

        $(function(){

            getClassInfo();

            $('select.class-info').change(function(){

                var name = $(this).attr('name');

                getClassInfo(name);

            });


            $('[name="method"]').change(function(){

                var dir = $('[name="dir"]').val();

                var file = $('[name="file"]').val();

                var method = $('[name="method"]').val();

                var _path = 'Admin';

                if(dir && dir != 0)
                    _path += '/' + dir;

                if(file && file != 0)
                    _path += '/' + file;

                if(method && method != 0)
                    _path += '/' + method;



                $('[name="name"]').val(_path);

            });

        })

        function getClassInfo(name)
        {

            var name = name ? name : 'dir' ;

            if(name == 'dir')
                $("[name='method']").html('<option value="0">请选择</option>');

            var _this = $('[name="'+name+'"]');

            if(!_this.val()){

                return false;

            }

            var _for = _this.attr('for');

            if(!_for)
                return false;





            var dir = $('[name="dir"]').val();

            var file = $('[name="file"]').val();

            var method = $('[name="method"]').val();

            if(name == 'dir')
                    var path = dir;

            if(name == 'file')
                var path = dir +'\\\\'+file;

            $.post("<?php echo U('Admin/Basic/Rule/create')?>",{

                "name": name,
                "path": path,


            },function(result){

                $("[name='"+ _for +"']").html('');

                if( result ) {

                    $("[name='"+ _for +"']").html('<option value="0">请选择</option>');

                    for (var i in result) {

                        if( !result.hasOwnProperty(result[i]) ) {

                            $("[name='"+ _for +"']").append('<option value="'+ result[i] +'">'+ result[i] +'</option>');

                        }

                    }

                }

                var dir = $('[name="dir"]').val();

                var file = $('[name="file"]').val();

                var method = $('[name="method"]').val();

                var _path = 'Admin';

                if(dir && dir != 0)
                    _path += '/' + dir;

                if(file && file != 0)
                    _path += '/' + file;

                if(method && method != 0)
                    _path += '/' + method;



                $('[name="name"]').val(_path);


            });

        }

    </script>
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists">
        <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">是否是菜单:</div>
        <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
            <div class="radio">
                <label class="radio-inline">
                    <input  name="ismenu" checked="checked" class="_data" value="1" type="radio"> 是
                </label>

                <label class="radio-inline">
                    <input  name="ismenu" class="_data" value="0" type="radio"> 否
                </label>
            </div>
        </div>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists">
        <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">附加规则 :</div>
        <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
            <input name="condition" type="text" autocomplete="off" class="form-control radius-none _data" placeholder="自定义规则">
        </div>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists">
        <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">图标 :</div>
        <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
            <input name="icon" type="text" autocomplete="off" class="form-control radius-none _data" placeholder="Bootstrap 字体图标">
        </div>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 padding-none lists">
        <div class="col-lg-2 col-md-3 col-xs-5 filed-name text-right">状态:</div>
        <div class="col-lg-3 col-md-5 col-xs-7 filed-from padding-none">
            <div class="radio">
                <label class="radio-inline">
                    <input type="radio" checked="checked" class="_data" name="status" value="1"> 正常
                </label>
                <label class="radio-inline">
                    <input type="radio" name="status" class="_data" value="0"> 禁用
                </label>
            </div>
        </div>
    </div>
    <div class="col-xs-12 col-md-12 col-lg-12 lists text-right">
        <input type="submit" name="dosubmit" value="保存" class="btn btn-success radius-none">
        <input type="reset"  value="重置" class="btn btn-info radius-none">
    </div>
</form>
<script>
    //表单异步提交回掉
    function ajaxRequestCallback(result,id)
    {

        switch(id){

            case 'create-rule':

                showMessage(result.msg,result.code,'','',2000);

        break;

        }

    }
</script>